import { createSlice } from '@reduxjs/toolkit'

interface IState {
  asideWidth: number // 侧边栏宽度
  theme: 'theme-light' | 'theme-dark' // 主题
  menuList: any[] // 菜单列表
  homeChuckList: any[] // 首页中的重点路由展示
  gameList: any[] // 游戏列表
  avatarList: any[string] // 头像列表
  avatar: string // 当前选中的头像
}

const initialState: IState = {
  asideWidth: localStorage.getItem('asideWidth') ? Number(localStorage.getItem('asideWidth')) : 200,
  theme: (localStorage.getItem('theme') as 'theme-light' | 'theme-dark') || 'theme-light',
  avatar: localStorage.getItem('avatar')
    ? (localStorage.getItem('avatar') as string)
    : 'https://img2.baidu.com/it/u=2908471763,924644777&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
  menuList: [
    {
      id: 1,
      title: '星际日志',
      path: '/home',
      icon: 'icon-shouye'
    },
    {
      id: 2,
      title: '星际日常',
      path: '/share',
      icon: 'icon-fenxiang'
    },
    {
      id: 3,
      title: '星际成果',
      path: '/product',
      icon: 'icon-xiangmu'
    },
    {
      id: 4,
      title: '星际维修站',
      path: '/upkeep',
      icon: 'icon-guanyuguwen'
    }
  ],
  homeChuckList: [
    {
      title: '个人分享',
      icon: 'icon-fenxiang',
      path: '/share',
      fileNum: 10,
      mainColor: '#22bf87',
      desc: '我的生活日常, 没事分享,心中所想'
    },
    {
      title: '项目&文件',
      icon: 'icon-xiangmu',
      path: '/product',
      fileNum: 15,
      mainColor: '#a048fa',
      desc: '本人自己上班之余开发的项目, 欢迎交流学习, 也可直接使用, 让我们一起遨游在代码的海洋中'
    },
    {
      title: '技术交流',
      icon: 'icon-kexuejishu-',
      path: '/upkeep',
      fileNum: 55,
      mainColor: '#ff7551',
      desc: '我在开发中遇到的一些问题, 以及解决方法, 欢迎大家交流学习'
    }
  ],
  avatarList: [
    'https://img2.baidu.com/it/u=2908471763,924644777&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img1.baidu.com/it/u=105862621,255524337&fm=253&fmt=auto&app=138&f=JPEG?w=893&h=800',
    'https://img0.baidu.com/it/u=3710176,727264440&fm=253&fmt=auto&app=120&f=JPEG?w=300&h=300',
    'https://img0.baidu.com/it/u=2966768524,3307222807&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
    'https://img2.baidu.com/it/u=3340200172,1741898850&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img1.baidu.com/it/u=3806746500,3956949612&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img1.baidu.com/it/u=2257236627,565479636&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img0.baidu.com/it/u=3303600817,3466172914&fm=253&fmt=auto&app=138&f=JPEG?w=380&h=380',
    'https://img0.baidu.com/it/u=3037964886,1321305075&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
    'https://img2.baidu.com/it/u=1591214298,3657665595&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img0.baidu.com/it/u=311890351,846091456&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img2.baidu.com/it/u=557810690,2448317856&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img2.baidu.com/it/u=3674362140,2448970246&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
    'https://img2.baidu.com/it/u=1649524169,2169378297&fm=253&fmt=auto?w=800&h=800',
    'https://img0.baidu.com/it/u=2498924256,4122643695&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800'
  ],
  gameList: [
    {
      title: '贪吃蛇',
      path: 'https://game.coderlt.chat/list/snake/index.html',
      img: 'snake.png'
    },
    {
      title: '飞机大战(普通)',
      path: 'https://game.coderlt.chat/list/airplane/index.html',
      img: 'myplane.gif'
    },
    {
      title: '飞机大战(高级)',
      path: 'https://game.coderlt.chat/list/airplane2/index.html',
      img: 'plane.png'
    }
  ]
}

const optionStore = createSlice({
  name: 'optionStore',
  initialState: initialState,
  reducers: {
    setAsideWidthActions(state, action) {
      state.asideWidth = action.payload
    },
    setThemeActions(state, action) {
      state.theme = action.payload
    },
    setAvatarActions(state, action) {
      state.avatar = action.payload
    }
  }
})

export const { setAsideWidthActions, setThemeActions, setAvatarActions } = optionStore.actions

export default optionStore.reducer
